/**
 * 统一管理后台用户相关的接口
*/
import { requestHttp } from "@/utils/requestHttp.ts";

//@ts-ignore
import { userInfoResponseData } from "./type.ts";


//分页获取订单列表信息
export const reqOrderList = (page:number, pageSize:number) => {
    return requestHttp<any>({
        url:"/manage/order",
        method:"get",
        params:{
            page:page,
            pageSize:pageSize
        }
    })
}

//更新一条订单信息
export const updateOrderInfo = (orderInfo) => {
    return requestHttp<any>({
        url:"/manage/order",
        method:"put",
        data:orderInfo
    })
}

//删除一条订单信息
export const reqDeleteOrder = (orderId:string) => {
    return requestHttp<any>({
        url:"/manage/order",
        method:"delete",
        params:{
            orderId
        }
    })
}

/**
 * 订单批量发货api接口
 * @param orderIds "orderIds":["777d65cb8e984d73816274d793257a68","10787e8d0780483e985b2dce1d09d6c5"]
 * @param orderState "orderState":"已发货",
 * @returns 
 */
export const reqBatchUpdateOrderState = (orderIds:string[], orderState?:string = "已发货") => {
    return requestHttp<any>({
        url:"/manage/orders",
        method:"put",
        data:{
            orderState:orderState,
            orderIds:orderIds
        }
    })
}

/**
 * 批量删除订单api接口
 * @param orderIds "orderIds":["8907bcee53c64f7fbc6dad0b559f7dda","e67b72bfd41e40428d0ef6bba20c1fca"]
 * @returns 
 */
export const reqBatchDeleteOrder = (orderIds:string[]) => {
    return requestHttp<any>({
        url:"/manage/orders",
        method:"delete",
        data:{
            orderIds:orderIds
        }
    })
}

/**
 * 按日期筛选订单api
 * startDate:"2024-02-21"
 * endDate:"2024-02-23"
 * 接口报错?axios的get请求方式限制携带请求体参数,无奈改成post请求。但是postman中get携带请求体参数是通过的
 */
export const reqOrderListByDate = (startDate:string, endDate:string) => {
    return requestHttp<any>({
        url:"/manage/orders",
        method:"post",
        data:{
            startDate:startDate,
            endDate:endDate
        }
    })
}

/**
 * 根据订单状态筛选订单
 * orderState = "已发货" || "已支付" || ...
 */
export const reqOrderListByState = (orderState:string) => {
    return requestHttp<any>({
        url:"/manage/orders/state",
        method:"get",
        params:{
            orderState:orderState
        }
    })
}

/**
 * 订单排序接口api
 * 对订单 创建时间create_time 更新时间 update_time 订单总价 order_total_price 进行升降序 排序
 * 查询参数：fieldName = create_time || update_time || order_total_price
 *          sortRule = asc(升序) || desc(降序)
 */
export const reqOrderListSort = (fieldName:string = create_time, sortRule:string = desc) => {
    return requestHttp<any>({
        url:"/manage/orders/sort",
        method:"get",
        params:{
            fieldName:fieldName,
            sortRule:sortRule
        }
    })
}

/**
 * 搜索订单api(通过订单id 或者 下单用户名 查询订单)
 * 请求体参数: userName = "ning0012" || orderId = ""
 * 注意实现通过id和用户名查询订单  需要根据条件传递对应的一个参数,不能传递两个参数
 * 接口报错?axios的get请求方式限制携带请求体参数,无奈改成post请求。但是postman中get携带请求体参数是通过的
 */
export const reqOrderListByOrderIdOrUsername = (params:string) => {
    let argument = "";
    if(params.length === 32) {
        argument = "orderId";
    } else {
        argument = "userName";
    }
    return requestHttp<any>({
        url:"/manage/orders/like",
        method:"post",
        data:{
            [argument]:params
        }
    })
}